<%@page contentType="text/html;charset=utf-8"%>
<%@include file="../../core/common.jsp"%>
<html>
<head>
<title></title>
</head>
<script>
	var ckzts = $.loadOption('${CTX}/mgt/sys/dict/option/ckzt');
	function ckzt_(value, row, index) {
		return ckzts[value];
	}
	function dy_(value, row, index) {
		var a = '<a href="${CTX}/mgt/t/ckd/dy?id=' + row.id + '" class="m-r-20">出库单</a>';
		a += '<a href="${CTX}/mgt/t/ckd/dymx?id=' + row.id + '" class="m-r-20">出库明细</a>';
		return a;
	}
</script>
<body>
	<div id="tb" class="toolbar">
		<form id="fm">
			<table class="form-layout w80">
				<tr>
					<td>合同编号：</td>
					<td><input name="search_htbh" class="easyui-textbox" /></td>
					<td>规格型号：</td>
					<td><input name="search_ggxh" class="easyui-combobox" data-options="url:'${CTX}/mgt/sys/dict/value/ph',editable:false,formatter:''" /></td>
					<td>出库期起：</td>
					<td><input name="search_begin" class="easyui-datebox" data-options="editable:false" /></td>
					<td>出库期止：</td>
					<td><input name="search_end" class="easyui-datebox" data-options="editable:false" /></td>
				</tr>
			</table>
		</form>
		<div style="float: left;">
			<shiro:hasPermission name="ckd:insert">
				<a id="insert" class="form-btn primary">
					<i class="fa fa-plus m-r-5"></i>添加
				</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="ckd:delete">
				<a id="delete" class="form-btn danger">
					<i class="fa fa-trash-o m-r-5"></i>删除
				</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="ckd:wcck">
				<a id="wcck" class="form-btn success">
					<i class="fa fa-check m-r-5"></i>完成出库
				</a>
			</shiro:hasPermission>
		</div>
		<div style="float: right;">
			<a id="find" class="form-btn success">
				<i class="fa fa-search m-r-5"></i>查询
			</a>
			<a id="reset" class="form-btn default">
				<i class="fa fa-undo m-r-5"></i>重置
			</a>
		</div>
		<div style="clear: both;"></div>
	</div>
	<table id="dg" class="easyui-datagrid" data-options="url:'${CTX}/mgt/t/ckd/find',toolbar:'#tb',pagination:true">
		<thead>
			<tr>
				<th data-options="field:'mx',width:50">明细</th>
				<th data-options="field:'htbh',width:100">合同编号</th>
				<th data-options="field:'ggxh',width:80">规格型号</th>
				<th data-options="field:'xf',width:200">需方</th>
				<th data-options="field:'wl',width:200">物流</th>
				<th data-options="field:'jz',width:80">净量(kg)</th>
				<th data-options="field:'ks',width:50">捆数</th>
				<th data-options="field:'ckzt',width:80,formatter:ckzt_">出库状态</th>
				<th data-options="field:'ckrq',width:100">出库日期</th>
				<th data-options="field:'dy',width:150,formatter:dy_">打印</th>
			</tr>
		</thead>
	</table>
</body>
<script>
	$(function() {
		$('#find').click(function() {
			$('#dg').datagrid('reload', $('#fm').serializeObject());
		});
		$('#reset').click(function() {
			$('#fm').form('reset');
			$('#find').click();
		});
		$('#insert').click(function() {
			parent.$.open({
				title : $(this).html(),
				url : '${CTX}/mgt/t/ckd/insert',
				end : function() {
					$('#find').click();
				}
			});
		});
		$('#delete').click(function() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				$.confirm('确定删除出库单', function() {
					$.mask();
					$.ajax({
						url : '${CTX}/mgt/t/ckd/delete',
						data : {
							id : row.id
						},
						success : function(data) {
							$.unmask();
							$.handle(data, function() {
								$('#find').click();
							});
						}
					});
				});
			} else {
				$.info('请选择出库单');
			}
		});
		$('#wcck').click(function() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				$.confirm('确认完成出库', function() {
					if (row.ckzt != '00' && row.ckzt !='10') {
						$.info('请选择计划中或操作中的出库单');
						return;
					}
					$.mask();
					$.ajax({
						url : '${CTX}/mgt/t/ckd/wcck',
						data : {
							id : row.id
						},
						success : function(data) {
							$.unmask();
							$.handle(data, function() {
								$('#find').click();
							});
						}
					});
				});
			} else {
				$.info('请选择出库单');
			}
		});
	});
</script>
</html>